﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CardGamesLibrary.Poker;

namespace CardGamesLibrary.UI.Poker
{
    public partial class PokerTableControl : UserControl
    {
        private PokerTable _pokerTable;

        public PokerTableControl()
        {
            InitializeComponent();
        }

        public void AssignTable(PokerTable pokerTable)
        {
            _pokerTable = pokerTable;
            _pokerTable.Cards.PropertyChanged += new PropertyChangedEventHandler(Cards_PropertyChanged);
            var controls = tableLayoutPanel1.Controls.OfType<PokerSeatControl>().ToArray();
            var i = 0;
            foreach (var tableSeat in _pokerTable.Seats.OfType<PokerSeat>())
            {
                controls[i].AssignSeat(tableSeat);
                i++;
            }

        }

        void Cards_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (_pokerTable.Cards.Count < 2)
            {
                frenchDeckCardControl1.SetCard(null);
                frenchDeckCardControl2.SetCard(null);
                frenchDeckCardControl3.SetCard(null);
                frenchDeckCardControl4.SetCard(null);
                frenchDeckCardControl5.SetCard(null);
                
            }
            if (_pokerTable.Cards.Count > 2)
            {
                frenchDeckCardControl1.SetCard(_pokerTable.Cards[0]);
                frenchDeckCardControl2.SetCard(_pokerTable.Cards[1]);
                frenchDeckCardControl3.SetCard(_pokerTable.Cards[2]);
                if (_pokerTable.Cards.Count > 3)
                {
                    frenchDeckCardControl4.SetCard(_pokerTable.Cards[3]);
                    if (_pokerTable.Cards.Count > 4)
                    {
                        frenchDeckCardControl5.SetCard(_pokerTable.Cards[4]);
                    }
                }
            }
        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void tableLayoutPanel1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void flowLayoutPanel1_Paint(object sender, PaintEventArgs e)
        {

        }

    }
}
